import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import poset.Item;
import poset.PosetSpace;
import poset.RectangularPosetSpace;

import spaces.VectorNode;


@SuppressWarnings("serial")
public class RectangularPosetSpaceViewer extends PosetSpaceViewer {
	
	private static final int NODE_RAD = 5;

	public RectangularPosetSpaceViewer(RectangularPosetSpace ps){
		super(ps);
	}
	
	public void paint(Graphics g){
		super.paint(g);
		if(((RectangularPosetSpace)posetSpace).getDims() == 2){
			double minX = ((RectangularPosetSpace)posetSpace).getMin(0);
			double maxX = ((RectangularPosetSpace)posetSpace).getMax(0);
			double minY = ((RectangularPosetSpace)posetSpace).getMin(1);
			double maxY = ((RectangularPosetSpace)posetSpace).getMax(1);
			double rangeX = maxX - minX;
			double rangeY = maxY - minY;
			double xRatio = rangeX/getWidth();
			double yRatio = rangeY/getHeight();
			double maxRatio = Math.max(xRatio,yRatio);

			// Draw Nodes
			for(VectorNode node : ((RectangularPosetSpace)posetSpace).getVectorSpace().getNodes()){
				if(node instanceof Item){
					g.setColor(Color.RED);
				} else {
					g.setColor(Color.GREEN);
				}
				g.fillOval( (int)(-(rangeX/maxRatio)/2+getWidth()/2 + (node.getPos().getValue(0)-minX)/maxRatio)-NODE_RAD, 
							(int)(-(rangeY/maxRatio)/2+getHeight()/2 + (node.getPos().getValue(1)-minY)/maxRatio)-NODE_RAD, NODE_RAD*2, NODE_RAD*2);
				/*
				g.drawString( node.getName(),
							  (int)(-(rangeX/maxRatio)/2+getWidth()/2 + (node.getPos().getValue(0)-minX)/maxRatio)-NODE_RAD, 
							  (int)(-(rangeY/maxRatio)/2+getHeight()/2 + (node.getPos().getValue(1)-minY)/maxRatio)-NODE_RAD);
							  */
			}
			
		}
		g.setColor(Color.YELLOW);
		g.drawString( "Tension: "+posetSpace.getTension(), 5, getHeight()-5 );
	}
}
